<template>
	<view style="padding: 15px;">
		<form @submit="formSubmit">
			<view class="uni-common-mt">
				<view class="uni-form-item uni-column user-input">
					<view class="title">分类</view>
					<view class="input">
						<picker @change="bindPickerChange" :value="cate" :range="array">
							<view class="uni-input">{{cate || '请选择'}}</view>
						</picker>
					</view>
				</view>
				<view class="fenjie"></view>
				<view class="uni-form-item uni-column user-input">
					<view class="title">内容</view>
					<view class="input">
						<u--textarea v-model="formData.content" placeholder="请输入内容"></u--textarea>
					</view>
				</view>
				<view class="fenjie"></view>
			</view>
			<button style="margin-top: 10px;" form-type="submit">提交</button>
		</form>
	</view>
</template>

<script>
	import {
		methods,
		onLoad
	} from '../../uni_modules/uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				formData: {
					cate: '',
					content: ''
				},
				cate: '',
				array: ['咨询服务', '我要求助', '投诉举报', '意见建议', '感谢表扬']
			}
		},
		onLoad() {

		},
		methods: {
			formSubmit(e) {

				if (!this.formData.cate) {
					uni.showToast({
						title: '请选择分类',
						icon: "none"
					});
					return
				}
				if (!this.formData.content) {
					uni.showToast({
						title: '请输入内容',
						icon: "none"
					});
					return
				}
				let openid = uni.getStorageSync('openid')
				
				if (this.formData.cate == '咨询服务') {
					this.formData.cate = '1'
				}else if(this.formData.cate == '我要求助') {
					this.formData.cate = '2'
				}else if(this.formData.cate == '投诉举报') {
					this.formData.cate = '3'
				}else if(this.formData.cate == '意见建议') {
					this.formData.cate = '4'
				}else if(this.formData.cate == '感谢表扬') {
					this.formData.cate = '5'
				}
				
				this.$app._post_form2('entry/wxapp/apicommon.addhotline', {
					openid: openid,
					cardid: '',
					cate: this.formData.cate,
					content: this.formData.content
				}, (result) => {
					
					console.log(result)
					uni.navigateTo({
						url: '/pages/global/successMessage?msg=提交成功'
					})
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.formData.cate = this.array[e.detail.value]
				this.cate = this.array[e.detail.value]
			}
		}
	}
</script>

<style scoped lang="scss">
	.user-input {
		width: 335px;
		margin: 20px auto;
		display: flex;

		.title {
			width: 90px;
		}

		.input {
			width: 280px;
			margin-left: 20px;
		}
	}

	.fenjie {
		height: 1px;
		background: #ddd;
		margin: 0 auto;
	}

	.up-button {
		width: 100%;
		height: 40px;
		background: #0096FB;
		border-radius: 4px;
		font-size: 16px;
		line-height: 40px;
		color: white;
		margin-top: 30px;
	}
</style>